ReEDS installation projections from the Solar Futures Study, published by DOE on 2021.
Current sections include:
Scenarios of Interest: o 95-by-35+Elec.Adv+DR , a.k.a. "Solar Futures Decarbonization + Electrification scenario"
import PV_ICE
import numpy as np
import pandas as pd
import os,sys
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})
plt.rcParams['figure.figsize'] = (12, 8)
import os
from pathlib import Path
testfolder = str(Path().resolve().parent.parent.parent / 'PV_ICE' / 'TEMP')
print ("Your simulation will be stored in %s" % testfolder)
PV_ICE.__version__
'v0.2.0+291.g5e1250d.dirty'
reedsFile = str(Path().resolve().parent.parent.parent.parent / 'December Core Scenarios ReEDS Outputs Solar Futures v3a.xlsx')
print ("Input file is stored in %s" % reedsFile)
REEDSInput = pd.read_excel(reedsFile,
# sheet_name="new installs PV (2)")
sheet_name="new installs PV")
#index_col=[0,2,3]) #this casts scenario, PCA and State as levels
rawdf = REEDSInput.copy()
rawdf.drop(columns=['State'], inplace=True)
rawdf.drop(columns=['Tech'], inplace=True) #tech=pvtotal from "new installs PV sheet", so can drop
rawdf.set_index(['Scenario','Year','PCA'], inplace=True)
rawdf.head(21)
r1 = PV_ICE.Simulation(name='Simulation1', path=testfolder)
r1.createScenario(name='cSi', massmodulefile=r'../baselines/RELOG/baseline_modules_mass_US_cSi.csv')
# MAC: I think we probably want noCircularity so everything goes to landfill and
# it's easy to calculate the 'BEST case for Recycling scenario'. Otherwise comment out...
r1.scenMod_noCircularity()
# This is really the cSi baseline, but got lazy to rename it so the new one will be baselineCdTe
baseline = r1.scenario['cSi'].dataIn_m
baseline = baseline.drop(columns=['new_Installed_Capacity_[MW]'])
baseline.set_index('year', inplace=True)
baseline.index = pd.PeriodIndex(baseline.index, freq='A') # A -- Annual
baseline.head()
r1.createScenario(name='CdTe', massmodulefile=r'../baselines/RELOG/baseline_modules_mass_US_CdTe.csv')
# MAC: I think we probably want noCircularity so everything goes to landfill and
# it's easy to calculate the 'BEST case for Recycling scenario'. Otherwise comment out...
r1.scenMod_noCircularity()
baselineCdTe = r1.scenario['CdTe'].dataIn_m
baselineCdTe = baselineCdTe.drop(columns=['new_Installed_Capacity_[MW]'])
baselineCdTe.set_index('year', inplace=True)
baselineCdTe.index = pd.PeriodIndex(baselineCdTe.index, freq='A') # A -- Annual
baselineCdTe.head()
# Set header dynamically
import csv
massmodulefile=r'../baselines/RELOG/baseline_modules_mass_US_cSi.csv'
with open(massmodulefile, newline='') as f:
reader = csv.reader(f)
row1 = next(reader) # gets the first line
row2 = next(reader) # gets the first line
row11 = 'year'
for x in row1[1:]:
row11 = row11 + ',' + x
row22 = 'year'
for x in row2[1:]:
row22 = row22 + ',' + x
# Load MarketShare File
marketsharefile = r'../baselines/SupportingMaterial/output_RELOG_cSi_CdTe_capacity_reeds.csv'
marketshare = pd.read_csv(marketsharefile)
# Not elegant but I need to trim down to ReEds year start which is 2010
marketshare = marketshare[marketshare['Year']>=2010].reset_index(drop=True)
marketshare.set_index('Year', inplace=True)
marketshare.head()
for ii in range (len(rawdf.unstack(level=1))):
PCA = rawdf.unstack(level=1).iloc[ii].name[1]
SCEN = rawdf.unstack(level=1).iloc[ii].name[0]
SCEN=SCEN.replace('+', '_')
filetitle = SCEN+'_cSI_'+PCA +'.csv'
subtestfolder = os.path.join(testfolder, 'PCAs_RELOG')
if not os.path.exists(subtestfolder):
os.makedirs(subtestfolder)
filetitle = os.path.join(subtestfolder, filetitle)
A = rawdf.unstack(level=1).iloc[ii]
A = A.droplevel(level=0)
A.name = 'new_Installed_Capacity_[MW]'
A = pd.DataFrame(A)
A.index=pd.PeriodIndex(A.index, freq='A')
A = pd.DataFrame(A)
B = A.copy()
B['new_Installed_Capacity_[MW]'] = B['new_Installed_Capacity_[MW]'] * marketshare['cSi Market Share'].values
B['new_Installed_Capacity_[MW]'] = B['new_Installed_Capacity_[MW]'] * 1000 # ReEDS file is in GW.
# Add other columns
B = pd.concat([B, baseline.reindex(A.index)], axis=1)
header = row11 + '\n' + row22 + '\n'
with open(filetitle, 'w', newline='') as ict:
# Write the header lines, including the index variable for
# the last one if you're letting Pandas produce that for you.
# (see above).
for line in header:
ict.write(line)
# savedata.to_csv(ict, index=False)
B.to_csv(ict, header=False)
filetitle = SCEN+'_CdTe_'+PCA +'.csv'
filetitle = os.path.join(subtestfolder, filetitle)
B = A.copy()
B['new_Installed_Capacity_[MW]'] = B['new_Installed_Capacity_[MW]'] * marketshare['CdTe Market Share'].values
B['new_Installed_Capacity_[MW]'] = B['new_Installed_Capacity_[MW]'] * 1000 # ReEDS file is in GW.
# Add other columns
B = pd.concat([B, baselineCdTe.reindex(B.index)], axis=1)
with open(filetitle, 'w', newline='') as ict:
# Write the header lines, including the index variable for
# the last one if you're letting Pandas produce that for you.
# (see above).
for line in header:
ict.write(line)
# savedata.to_csv(ict, index=False)
B.to_csv(ict, header=False)
PCAs = list(rawdf.unstack(level=2).iloc[0].unstack(level=0).index.unique())
SFscenarios = ['95-by-35_Elec.Adv_DR_cSi', '95-by-35_Elec.Adv_DR_CdTe']
from geopy.geocoders import Nominatim
from geopy.point import Point
# initialize Nominatim API
geolocator = Nominatim(user_agent="geoapiExercises")
GISfile = str(Path().resolve().parent.parent.parent / 'gis_centroid_n.xlsx')
GIS = pd.read_excel(GISfile)
GIS = GIS.set_index('id')
GIS
| long | lat | country | |
|---|---|---|---|
| id | |||
| p1 | -121.452252 | 47.820991 | USA |
| p10 | -117.159039 | 35.120104 | USA |
| p100 | -78.257714 | 38.791108 | USA |
| p101 | -82.192477 | 28.708695 | USA |
| p102 | -80.563731 | 26.677092 | USA |
| ... | ... | ... | ... |
| p201 | -116.933572 | 32.485742 | MEX |
| p202 | -116.345053 | 31.558623 | MEX |
| p203 | -115.418298 | 32.607552 | MEX |
| p204 | -114.836778 | 32.379719 | MEX |
| p205 | -110.589268 | 24.163894 | MEX |
205 rows × 3 columns
GIS.reset_index(inplace=True)
for row in range(len(GIS)):
Longitude = GIS.loc[row].long
Latitude = GIS.loc[row].lat
location = geolocator.reverse(Point(Latitude, Longitude))
address = location.raw['address']
city = address.get('city', '')
county = address.get('county', '')
state = address.get('state', '')
GIS.loc[row].location = str(county + ", " + state)
def city_state_country(row):
coord = f"{row['lat']}, {row['long']}"
location = geolocator.reverse(coord, exactly_one=True)
address = location.raw['address']
city = address.get('city', '')
county = address.get('county', '')
state = address.get('state', '')
country = address.get('country', '')
row['city'] = city
row['county'] = county
row['state'] = state
row['country'] = country
return row
GIS = GIS.apply(city_state_country, axis=1)
GIS_us = GIS[GIS.country == 'United States']
Geographic area dictionaries:
GIS
| id | long | lat | country | city | county | state | |
|---|---|---|---|---|---|---|---|
| 0 | p1 | -121.452252 | 47.820991 | United States | Snohomish County | Washington | |
| 1 | p10 | -117.159039 | 35.120104 | United States | CAL Fire San Bernardino Unit | California | |
| 2 | p100 | -78.257714 | 38.791108 | United States | Warren County | Virginia | |
| 3 | p101 | -82.192477 | 28.708695 | United States | Sumter County | Florida | |
| 4 | p102 | -80.563731 | 26.677092 | United States | Palm Beach County | Florida | |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 200 | p201 | -116.933572 | 32.485742 | México | Tijuana | Municipio de Tijuana | Baja California |
| 201 | p202 | -116.345053 | 31.558623 | México | Municipio de Ensenada | Baja California | |
| 202 | p203 | -115.418298 | 32.607552 | México | Mexicali | Municipio de Mexicali | Baja California |
| 203 | p204 | -114.836778 | 32.379719 | México | San Luis Río Colorado | Sonora | |
| 204 | p205 | -110.589268 | 24.163894 | México | Municipio de La Paz | Baja California Sur |
205 rows × 7 columns
GIS_us
| id | long | lat | country | city | county | state | |
|---|---|---|---|---|---|---|---|
| 0 | p1 | -121.452252 | 47.820991 | United States | Snohomish County | Washington | |
| 1 | p10 | -117.159039 | 35.120104 | United States | CAL Fire San Bernardino Unit | California | |
| 2 | p100 | -78.257714 | 38.791108 | United States | Warren County | Virginia | |
| 3 | p101 | -82.192477 | 28.708695 | United States | Sumter County | Florida | |
| 4 | p102 | -80.563731 | 26.677092 | United States | Palm Beach County | Florida | |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 152 | p96 | -80.470185 | 33.666562 | United States | Clarendon County | South Carolina | |
| 153 | p97 | -81.469485 | 35.703545 | United States | Burke County | North Carolina | |
| 154 | p98 | -78.063174 | 35.438992 | United States | Wayne County | North Carolina | |
| 155 | p99 | -78.022226 | 37.641073 | United States | Powhatan County | Virginia | |
| 168 | p169 | -99.491584 | 27.345318 | United States | Webb County | Texas |
135 rows × 7 columns
from itertools import chain
us_regions = {'New England' : set(['Connecticut', 'Maine', 'Massachusetts', 'New Hampshire', 'Rhode Island', 'Vermont']),
'Middle Atlantic': set(['Delaware', 'the District of Columbia', 'Maryland', 'New Jersey', 'New York', 'Pennsylvania', 'Virginia', 'West Virginia']),
'South Atlantic': set(['Georgia', 'North Carolina', 'South Carolina']),
'Midwest': set(['Illinois', 'Indiana', 'Iowa', 'Kansas', 'Michigan', 'Minnesota', 'Missouri', 'Nebraska', 'North Dakota', 'Ohio', 'South Dakota', 'Wisconsin']),
'Gulf': set(['Texas', 'Louisiana', 'Mississippi', 'Alabama', 'Florida']),
'Southwest': set(['Nevada', 'Oklahoma', 'Utah']),
'Mountain': set(['Arizona', 'Colorado', 'Idaho', 'Montana', 'New Mexico', 'Wyoming']),
'Pacific Coast': set(['California', 'Oregon', 'Washington', 'Alaska', 'Hawaii'])}
d = {'a': set(['uno','dos','tres']), 'b': set(['tres', 'cuatro'])}
keys, values = map(chain.from_iterable, zip(*((k*len(v), v) for k, v in d.items())))
df = pd.DataFrame({'letter': list(keys), 'value': list(values)})
keys, values = map(chain.from_iterable, zip(*((k*len(v), v) for k, v in us_regions.items())))
#us_regions_df = pd.DataFrame({'region': list(keys), 'state': list(values)})
GIS_us.state.unique()
array(['Washington', 'California', 'Virginia', 'Florida', 'Michigan',
'Indiana', 'Kentucky', 'Ohio', 'Pennsylvania', 'West Virginia',
'Nevada', 'Maryland', 'Delaware', 'New Jersey', 'New York',
'Vermont', 'New Hampshire', 'Massachusetts', 'Connecticut',
'Rhode Island', 'Maine', 'Idaho', 'Montana', 'Wyoming', 'Utah',
'Arizona', 'New Mexico', 'South Dakota', 'Colorado',
'North Dakota', 'Nebraska', 'Minnesota', 'Iowa', 'Wisconsin',
'Texas', 'Oklahoma', 'Oregon', 'Kansas', 'Missouri', 'Arkansas',
'Louisiana', 'Illinois', 'Mississippi', 'Alabama', 'Tennessee',
'Georgia', 'South Carolina', 'North Carolina'], dtype=object)
len(GIS_us)
135
Keeping track of each scenario as its own PV ICE Object.
Path().resolve().parent
PosixPath('/Users/mmendez/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE')
baselinefolder = os.path.join(Path().resolve().parent, 'baselines')
baselinefolder
'/Users/mmendez/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/baselines'
testfolder
'/Users/mmendez/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/TEMP'
#for ii in range (0, 1): #len(scenarios):
i = 0
r1 = PV_ICE.Simulation(name=SFscenarios[i], path=testfolder)
for jj in range (0, len(PCAs)):
filetitle = SFscenarios[i]+'_'+PCAs[jj]+'.csv'
filetitle = os.path.join(testfolder, 'PCAs_RELOG', filetitle)
r1.createScenario(name=PCAs[jj], massmodulefile=filetitle)
r1.scenario[PCAs[jj]].addMaterials(['glass', 'silicon', 'silver', 'copper', 'aluminium_frames', 'encapsulant', 'backsheet'], baselinefolder=baselinefolder)
# All -- but these where not included in the Reeds initial study as we didnt have encapsulant or backsheet
# r1.scenario[PCAs[jj]].addMaterials(['glass', 'silicon', 'silver', 'copper', 'aluminium_frames', 'encapsulant', 'backsheet'], baselinefolder=r'..\baselines')
r1.scenario[PCAs[jj]].latitude = GIS.loc[PCAs[jj]].lat
r1.scenario[PCAs[jj]].longitude = GIS.loc[PCAs[jj]].long
r1.trim_Years(startYear=2010, endYear=2050)
i = 1
r2 = PV_ICE.Simulation(name=SFscenarios[i], path=testfolder)
for jj in range (0, len(PCAs)):
filetitle = SFscenarios[i]+'_'+PCAs[jj]+'.csv'
filetitle = os.path.join(testfolder, 'PCAs_RELOG', filetitle)
r2.createScenario(name=PCAs[jj], massmodulefile=filetitle)
# MAC Add here the materials you want.
r2.scenario[PCAs[jj]].addMaterials(['cadmium', 'tellurium', 'glass_cdte', 'aluminium_frames_cdte', 'encapsulant_cdte', 'copper_cdte'], baselinefolder=baselinefolder)
# All -- but these where not included in the Reeds initial study as we didnt have encapsulant or backsheet
# r2.scenario[PCAs[jj]].addMaterials(['glass', 'silicon', 'silver', 'copper', 'aluminium_frames', 'encapsulant', 'backsheet'], baselinefolder=r'..\baselines')
r2.scenario[PCAs[jj]].latitude = GIS.loc[PCAs[jj]].lat
r2.scenario[PCAs[jj]].longitude = GIS.loc[PCAs[jj]].long
r2.trim_Years(startYear=2010, endYear=2050)
path = /Users/mmendez/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/TEMP Adding Mass AND Energy files for: glass Adding Mass AND Energy files for: silicon Adding Mass AND Energy files for: silver Adding Mass AND Energy files for: copper
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) Input In [36], in <cell line: 5>() 7 filetitle = os.path.join(testfolder, 'PCAs_RELOG', filetitle) 8 r1.createScenario(name=PCAs[jj], massmodulefile=filetitle) ----> 9 r1.scenario[PCAs[jj]].addMaterials(['glass', 'silicon', 'silver', 'copper', 'aluminium_frames', 'encapsulant', 'backsheet'], baselinefolder=baselinefolder) 10 # All -- but these where not included in the Reeds initial study as we didnt have encapsulant or backsheet 11 # r1.scenario[PCAs[jj]].addMaterials(['glass', 'silicon', 'silver', 'copper', 'aluminium_frames', 'encapsulant', 'backsheet'], baselinefolder=r'..\baselines') 12 r1.scenario[PCAs[jj]].latitude = GIS.loc[PCAs[jj]].lat File ~/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/main.py:1740, in Scenario.addMaterials(self, materials, baselinefolder, nameformat) 1737 else: 1738 filematenergy = None -> 1740 self.material[mat] = Material(mat, massmatfile = filematmass, 1741 energymatfile = filematenergy) File ~/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/main.py:1780, in Material.__init__(self, materialname, massmatfile, energymatfile) 1776 except: 1777 raise Exception('Interactive load failed. Tkinter not supported'+ 1778 'on this system. Try installing X-Quartz and reloading') -> 1780 data, meta = _readPVICEFile(massmatfile) 1782 self.massmatfile = massmatfile 1783 self.matmetdataIn_m = meta File ~/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/main.py:39, in _readPVICEFile(file) 37 def _readPVICEFile(file): ---> 39 csvdata = open(str(file), 'r', encoding="UTF-8") 40 csvdata = open(str(file), 'r', encoding="UTF-8-sig") 41 firstline = csvdata.readline() FileNotFoundError: [Errno 2] No such file or directory: '/Users/mmendez/Documents/Postdoc/Software_dev/PV_ICE/PV_ICE/baselines/baseline_material_mass_copper.csv'
PERFECTMFG = True
if PERFECTMFG:
r1.scenMod_PerfectManufacturing()
r2.scenMod_PerfectManufacturing()
title_Method = 'PVICE_PerfectMFG'
else:
title_Method = 'PVICE'
r1.calculateMassFlow()
r2.calculateMassFlow()
print("PCAs:", r1.scenario.keys())
print("Module Keys:", r1.scenario[PCAs[jj]].dataIn_m.keys())
print("Material Keys: ", r1.scenario[PCAs[jj]].material['glass'].matdataIn_m.keys())
"""
r1.plotScenariosComparison(keyword='Cumulative_Area_disposedby_Failure')
r1.plotMaterialComparisonAcrossScenarios(material='silicon', keyword='mat_Total_Landfilled')
r1.scenario['p1'].dataIn_m.head(21)
r2.scenario['p1'].dataIn_m.head(21)
"""
pass
r1.aggregateResults()
r2.aggregateResults()
datay = r1.USyearly
datac = r1.UScum
datay_CdTe = r2.USyearly
datac_CdTe = r2.UScum
datay.keys()
filter_colc = [col for col in datay if col.startswith('WasteEOL')]
datay[filter_colc].to_csv('PVICE_RELOG_PCA_cSi_WasteEOL.csv')
filter_colc = [col for col in datay_CdTe if col.startswith('WasteEOL')]
datay_CdTe[filter_colc].to_csv('PVICE_RELOG_PCA_CdTe_WasteEOL.csv')
datay
#!pip install geopy
#!pip install Nominatim
from geopy.geocoders import Nominatim
GISfile = os.path.join(str(Path().resolve().parent.parent.parent.parent), 'gis_centroid_n.xlsx')
#GISfile = r'C:\Users\sayala\Documents\GitHub\gis_centroid_n.xlsx'
GIS = pd.read_excel(GISfile)
GIS.head(2)
geolocator = Nominatim(user_agent="geoapiExercises")
def city_state_country(row):
coord = f"{row['lat']}, {row['long']}"
location = geolocator.reverse(coord, exactly_one=True)
address = location.raw['address']
city = address.get('city', '')
county = address.get('county', '')
state = address.get('state', '')
country = address.get('country', '')
row['city'] = city
row['county'] = county
row['state'] = state
row['country'] = country
return row
GIS = GIS.apply(city_state_country, axis=1)
GIS_us = GIS[GIS.country == 'United States']
GIS_us
cost_factors_file = os.path.join(str(Path().resolve().parent.parent.parent.parent), 'RICE', 'data', 'cost_factors.xlsx')
#cost_factors_file = r'C:\Users\sayala\Documents\GitHub\RICE\data\cost_factors.xlsx'
cost_factors = pd.read_excel(cost_factors_file)
cost_factors.head(2)
GIS_us['labor rate factor'] = np.nan
GIS_us['productivity factor'] = np.nan
GIS_us['relative labor rate ratio'] = np.nan
GIS_us['relative productivity factor ratio'] = np.nan
GIS_us['area cost factor'] = np.nan
for rr in range (0, len(cost_factors)):
# print(cost_factors.loc[rr]['state'])
GIS_us.loc[GIS_us['state'] == cost_factors.loc[rr]['state'],'labor rate factor'] = cost_factors.loc[rr]['labor rate factor']
GIS_us.loc[GIS_us['state'] == cost_factors.loc[rr]['state'],'productivity factor'] = cost_factors.loc[rr]['productivity factor']
GIS_us.loc[GIS_us['state'] == cost_factors.loc[rr]['state'],'relative labor rate ratio'] = cost_factors.loc[rr]['relative labor rate ratio']
GIS_us.loc[GIS_us['state'] == cost_factors.loc[rr]['state'],'relative productivity factor ratio'] = cost_factors.loc[rr]['relative productivity factor ratio']
GIS_us.loc[GIS_us['state'] == cost_factors.loc[rr]['state'],'area cost factor'] = cost_factors.loc[rr]['area cost factor']
# sanity check rr = 2
GIS_us[GIS_us['state'] == cost_factors.loc[rr]['state']]